package com.hpjpw.ido.controller;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hpjpw.ido.domain.Communication;
import com.hpjpw.ido.service.ICommunicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 聊天内容Controller
 * 
 * @author hpj
 * @date 2021-01-02
 */
@Api(value ="CommunicationController")
@RestController
@RequestMapping("/ido/communication")
public class CommunicationController extends BaseController
{
    @Autowired
    private ICommunicationService communicationService;

    /**
     * 查询聊天内容列表
     */
    @PreAuthorize("@ss.hasPermi('ido:communication:list')")
    @GetMapping("/list")
    @ApiOperation("查询聊天内容列表")
    public TableDataInfo list(Communication communication)
    {
        startPage();
        List<Communication> list = communicationService.selectCommunicationList(communication);
        return getDataTable(list);
    }

    /**
     * 导出聊天内容列表
     */
    @PreAuthorize("@ss.hasPermi('ido:communication:export')")
    @Log(title = "聊天内容", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出聊天内容列表")
    public AjaxResult export(Communication communication)
    {
        List<Communication> list = communicationService.selectCommunicationList(communication);
        ExcelUtil<Communication> util = new ExcelUtil<Communication>(Communication.class);
        return util.exportExcel(list, "communication");
    }

    /**
     * 获取聊天内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('ido:communication:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取聊天内容详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(communicationService.selectCommunicationById(id));
    }

    /**
     * 新增聊天内容
     */
    @PreAuthorize("@ss.hasPermi('ido:communication:add')")
    @Log(title = "聊天内容", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增聊天内容")
    public AjaxResult add(@RequestBody Communication communication)
    {
        return toAjax(communicationService.insertCommunication(communication));
    }

    /**
     * 修改聊天内容
     */
    @PreAuthorize("@ss.hasPermi('ido:communication:edit')")
    @Log(title = "聊天内容", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改聊天内容")
    public AjaxResult edit(@RequestBody Communication communication)
    {
        return toAjax(communicationService.updateCommunication(communication));
    }

    /**
     * 删除聊天内容
     */
    @PreAuthorize("@ss.hasPermi('ido:communication:remove')")
    @Log(title = "聊天内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除聊天内容")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(communicationService.deleteCommunicationByIds(ids));
    }
}
